unit UDMGeral;

interface

uses
  SysUtils, Classes, DBXpress, DB, SqlExpr, Provider, FMTBcd, DBClient,
  DBLocal, Messages,Dialogs;

type
  TDMGeral = class(TDataModule)
    SQLConnection: TSQLConnection;
    SQLCTransacao: TSQLConnection;
    SQLConnectionLocal: TSQLConnection;
    SQLDAux: TSQLDataSet;
    procedure DataModuleCreate(Sender: TObject);
    procedure SQLConnectionBeforeConnect(Sender: TObject);
    procedure SQLCTransacaoBeforeConnect(Sender: TObject);
    procedure SQLConnectionLocalBeforeConnect(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DMGeral: TDMGeral;
  posPass :Integer;

implementation

uses UGeral;

{$R *.dfm}

procedure TDMGeral.DataModuleCreate(Sender: TObject);
begin
  if AliasGeral <> '' then
  begin
    SQLConnection.Connected:=false;
    SQLConnection.Connected:=True;

    SQLCTransacao.Connected:=false;
    SQLCTransacao.Connected:=True;
  end;

  if AliasLocal <> '' then
  begin
    SQLConnectionLocal.Connected:=false;
    SQLConnectionLocal.Connected:=True;
  end;

end;

procedure TDMGeral.SQLConnectionBeforeConnect(Sender: TObject);
begin
 SQLConnection.ConnectionName:=AliasGeral;
 SQLConnection.LoadParamsOnConnect:=False;
 SQLConnection.LoadParamsFromIniFile(GetCurrentDir + '\dbxconnections.ini');
 
 posPass:=SQLConnection.Params.IndexOf('Password=');
 SQLConnection.Params.Delete(posPass);
 SQLConnection.Params.Insert(posPass,'Password=172026');

 SQLConnection.LoadParamsOnConnect:=true;
end;

procedure TDMGeral.SQLCTransacaoBeforeConnect(Sender: TObject);
begin
 SQLCTransacao.ConnectionName:=AliasGeral;
 SQLCTransacao.LoadParamsOnConnect:=False;
 SQLCTransacao.LoadParamsFromIniFile(GetCurrentDir + '\dbxconnections.ini');

 posPass:=SQLCTransacao.Params.IndexOf('Password=');
 SQLCTransacao.Params.Delete(posPass);
 SQLCTransacao.Params.Insert(posPass,'Password=172026');
 SQLCTransacao.LoadParamsOnConnect:=true;
end;

procedure TDMGeral.SQLConnectionLocalBeforeConnect(Sender: TObject);
begin
 SQLConnectionLocal.ConnectionName:=AliasLocal;
 SQLConnectionLocal.LoadParamsOnConnect:=False;
 SQLConnectionLocal.LoadParamsFromIniFile(GetCurrentDir + '\dbxconnections.ini');

 posPass:=SQLConnectionLocal.Params.IndexOf('Password=');
 SQLConnectionLocal.Params.Delete(posPass);
 SQLConnectionLocal.Params.Insert(posPass,'Password=172026');
 SQLConnectionLocal.LoadParamsOnConnect:=true;
end;

end.
